// 存放页面所有共同调用的功能性函数
export function getPower(vipLevel) {  //获取页面所有功能的最低权限等级（各种登录接口都要调用）
  return new Promise((resolve, reject) => {
    this.$axios({
      method: 'get',
      params:{
        level:vipLevel
      },
      url: '/api/module/getmodule'
    }).then(res => {
      this.isShowApp = true;
      if (res.data.code == 0) {
        resolve(res.data.data);
        let roots = res.data.data;
        let rootObj = [];
        //添加权限对象
        // console.log('会员等级：',vipLevel);
        // alert(vipLevel);
        if (vipLevel == 1) {
          rootObj = roots['listsvip'];
        } else if (vipLevel == 2) {
          rootObj = roots['listplusvip'];
        } else if (vipLevel == 3) {
          rootObj = roots['listHalloween'];
        } else if (vipLevel == 4) {
          rootObj = roots['listvip'];
        } else if (vipLevel == 5) {
          rootObj = roots['listsvipPersonal'];
        } else {
          rootObj = roots['listfree'];
        }
        let initRootObj = {};

        for (let i = 0; i < rootObj.length; i++) {
          let parentLevel = rootObj[i];
          initRootObj[parentLevel.id] = {
            owner: parentLevel.owner,
            ownerMinLevel:parentLevel.ownerMinLevel
          };
          for (let j = 0; j < rootObj[i].subList.length; j++) {
            let childLevel = rootObj[i].subList[j];
            let idKey = childLevel.id;
            initRootObj[parentLevel.id][idKey] = {ownerMinLevel:childLevel.ownerMinLevel,owner:childLevel.owner};
          }
        }
        // console.log('处理后的权限对象：',initRootObj);
        this.$store.commit('userRoot', initRootObj);
      }else{
        reject(res.data);
      }
    })
    .catch(error => {
      reject(error);
      console.log(error);
    });
  })
}
